# -*- coding: utf-8 -*-
import cv2 as cv
import matplotlib.pyplot as plt

img = cv.imread("photos/dog.jpg")
cv.imshow("Dog", img)

gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow("gray", gray)

# gray scale histogram
gray_hist = cv.calcHist([gray], [0], None, [256], [0,256])

plt.figure()
plt.title("gray scale histogram")
plt.xlabel("Bins")
plt.ylabel("number of pixels")
plt.plot(gray_hist)
plt.xlim([0,256])
plt.show()

# color histogram
plt.figure()
plt.title("color histogram")
plt.xlabel("Bins")
plt.ylabel("number of pixels")
colors = ("b", "g", "r")
for i,col in enumerate(colors):
    hist = cv.calcHist([img], [i], None, [256], [0,256])
    plt.plot(hist, color=col)
    plt.xlim([0,256])
    
cv.waitKey(0)